﻿@model IEnumerable<WeProjectsModel.News>

@{
    ViewBag.Title = "News";
    int usrId = int.Parse(Membership.GetUser().ProviderUserKey.ToString());
}

@Html.Partial("_projectMenu",(int)ViewBag.ProjectID)
<h2>@ViewBag.projectTitle: 新闻</h2>

@if (!ViewBag.HideCreateButton)
{ 
<div>
    @Html.ActionLink("发布新闻", "Create", new { id = ViewBag.ProjectID }, new { @class = "btn btn-info btn-lg" })
</div>
}

<table class="table">
    <tr>
        <th>
            标题
        </th>
        @*<th>
            @Html.DisplayNameFor(model => model.NewsContent)
        </th>*@
        <th>发布人</th>
        <th>
            发布日期
        </th>
        <th class="text-center">
            是否公开
        </th>
        <th>操作</th>
    </tr>

@foreach (var item in Model)
{
    <tr>
        <td>
            @Html.ActionLink(item.Title, "../News/Details", new { id = item.ID })
        </td>
        @*<td>
            @Html.DisplayFor(modelItem => item.NewsContent)
        </td>*@
        <td>
            @Html.DisplayFor(modelItem => item.Author.DisplayName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.PublishDate)
        </td>
        <td>@if(item.Project.OwnerID==usrId){
            @Html.Raw((item.isPublic == 0) ? "否 " + Html.ActionLink("点此公开", "NewsPublic", new { projectId = ViewBag.ProjectID, newsId = item.ID, pub = 1 }, new { @class = "btn btn-success btn-small" }) : "是 " + Html.ActionLink("取消公开", "NewsPublic", new { projectId = ViewBag.ProjectID, newsId = item.ID, pub = 0 }, new { @class = "btn btn-danger btn-small" }))
        }
            else
            {
                if(item.isPublic==null||item.isPublic==0){ @Html.Label("否") }else{@Html.Raw("是")}
            }                                                                                                                                                                                                                                                                                              
        </td>
        <td>
            @if (item.Project.OwnerID == usrId || item.AuthorID == usrId || Roles.IsUserInRole("sysadmin")) { 
            @Html.ActionLink("编辑", "../News/Edit", new { id = item.ID }, new { @class = "btn btn-success btn-small" })<span>&nbsp;</span>
            @Html.ActionLink("删除", "../News/Delete", new { id=item.ID }, new { @class = "btn btn-danger btn-small" })
            }
        </td>
    </tr>
}

</table>
